import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Routes {
  static const String home = "/";
  static const String post = "post";

  static Route<T> pageRoute<T>(RouteSettings settings, WidgetBuilder page,
      {int duration = 300}) {
    return UpwardsPageRoute(builder: page);
  }
}

class UpwardsPageRoute<T> extends PageRoute<T> {
  UpwardsPageRoute({
    required this.builder,
    this.transitionDuration = const Duration(milliseconds: 300),
    this.opaque = true,
    this.barrierDismissible = false,
    this.barrierColor,
    this.barrierLabel,
    this.maintainState = true,
  });

  final WidgetBuilder builder;

  @override
  final Duration transitionDuration;

  @override
  final bool opaque;

  @override
  final bool barrierDismissible;

  @override
  final Color? barrierColor;

  @override
  final String? barrierLabel;

  @override
  final bool maintainState;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) =>
      builder(context);

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    final Tween<Offset> _bottomUpTween = Tween<Offset>(
      begin: const Offset(0.0, 0.25),
      end: Offset.zero,
    );
    return SlideTransition(
      position: _bottomUpTween.animate(
          CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
      child: builder(context),
    );
  }
}
